

import { base64toFile } from "./base64ToStream";

import { upload } from "./request";

// 上传
const uploadImage = async ({
    imgBase64 = "",
    apiurl = '/upload-api/image',
    params = {},
    success = () => { },
    failure = () => { },
    complete = () => { }
}) => {

    try {
        let file = base64toFile(imgBase64);
        console.log("base64转换成file\n", file)
        let formData = new FormData();
        formData.append('image', file);//看上图，我用的是test
        let url = process.env.VUE_APP_SERVER_URL + apiurl;
        const res = await upload({
            url,
            params: {
                ...params
            },
            data: formData,
        })
        console.log("27上传结果：\n", res)
        success(res)
        
    } catch (error) {
        failure(error)

    } finally {
        complete()
    }
}
export default uploadImage